/**
 * 
 */
package de.sinnlosimnetz.forum.util;

import java.sql.Connection;
import java.sql.SQLException;

import de.sinnlosimnetz.forum.database.Database;

/**
 * @author Henning D
 *
 */
public abstract class SinAbstractConnector implements SinConnector
{
	protected SinConnectorEnum dbms = null;
	
	protected String dbUrl = null;
	
	protected int dbPort = 0;
	
	protected String dbName = null;
	
	protected String dbUser = null;
	
	protected String dbPass = null;

	public SinAbstractConnector()
	{}

	/**
	 * Kostruktor mit allen Werten
	 * 
	 * @param dbms Datenbank-Management-System
	 * @param dbUrl Datenbank-Ip
	 * @param dbPort Datenbank-Port
	 * @param dbName Datenbank-Name
	 * @param dbUser Datenbank-Benutzer
	 * @param dbPass Datenbank-Passwort
	 */
	public SinAbstractConnector(SinConnectorEnum dbms, String dbUrl, int dbPort,
			String dbName, String dbUser, String dbPass)
	{
		super();
		this.dbms = dbms;
		this.dbUrl = dbUrl;
		this.dbPort = dbPort;
		this.dbName = dbName;
		this.dbUser = dbUser;
		this.dbPass = dbPass;
	}

	public SinAbstractConnector(Database database)
	{
		this(SinConnectorEnum.getInstance(database.getDbms()), database.getDbhost(), database.getDbport(), 
				database.getDbname(), database.getDbuser(), database.getDbpass());
	}
	
	/* (non-Javadoc)
	 * @see de.sinnlosimnetz.forum.util.SinConnector#getConnection()
	 */
	public abstract Connection getConnection();
	
	/* (non-Javadoc)
	 * @see de.sinnlosimnetz.forum.util.SinConnector#closeConnection()
	 */
	public abstract void closeConnection() throws SQLException, Exception;
	
	/**
	 * Liefert dbms
	 *
	 * @return dbms
	 */
	public SinConnectorEnum getDbms()
	{
		return dbms;
	}

	/**
	 * Setzt dbms
	 *
	 * @param dbms das zu setzende dbms
	 */
	public void setDbms(SinConnectorEnum dbms)
	{
		this.dbms = dbms;
	}

	/**
	 * Liefert dbUrl
	 *
	 * @return dbUrl
	 */
	public String getDbUrl()
	{
		return dbUrl;
	}

	/**
	 * Setzt dbUrl
	 *
	 * @param dbUrl das zu setzende dbUrl
	 */
	public void setDbUrl(String dbUrl)
	{
		this.dbUrl = dbUrl;
	}

	/**
	 * Liefert dbPort
	 *
	 * @return dbPort
	 */
	public int getDbPort()
	{
		return dbPort;
	}

	/**
	 * Setzt dbPort
	 *
	 * @param dbPort das zu setzende dbPort
	 */
	public void setDbPort(int dbPort)
	{
		this.dbPort = dbPort;
	}

	/**
	 * Liefert dbName
	 *
	 * @return dbName
	 */
	public String getDbName()
	{
		return dbName;
	}

	/**
	 * Setzt dbName
	 *
	 * @param dbName das zu setzende dbName
	 */
	public void setDbName(String dbName)
	{
		this.dbName = dbName;
	}

	/**
	 * Liefert dbUser
	 *
	 * @return dbUser
	 */
	public String getDbUser()
	{
		return dbUser;
	}

	/**
	 * Setzt dbUser
	 *
	 * @param dbUser das zu setzende dbUser
	 */
	public void setDbUser(String dbUser)
	{
		this.dbUser = dbUser;
	}

	/**
	 * Liefert dbPass
	 *
	 * @return dbPass
	 */
	public String getDbPass()
	{
		return dbPass;
	}

	/**
	 * Setzt dbPass
	 *
	 * @param dbPass das zu setzende dbPass
	 */
	public void setDbPass(String dbPass)
	{
		this.dbPass = dbPass;
	}
}
